package com.minio.config;

import com.minio.properties.MinioProperties;
import com.minio.MinioService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Configuration
public class MinioConfiguration {

    @Bean
    public MinioService minioService(){
        return new MinioService();
    }

    @Bean
    public MinioProperties minioProperties(){
        return new MinioProperties();
    }

    @Bean(name = "minioThreadPool")
    public ThreadPoolExecutor threadPoolExecutor() {
        int processors = Runtime.getRuntime().availableProcessors();
        return new ThreadPoolExecutor(processors,
                processors * 2,
                5,
                TimeUnit.MINUTES,
                new ArrayBlockingQueue<>(1024),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.DiscardPolicy());
    }
}
